<template>
  <!-- 网站导航部分 -->
  <div class="menu-container">
    <RouterLink
      v-for="item in links"
      :key="item.name"
      :to="{name: item.name}"
      :exact="item.exact"
      active-class="selected"
      exact-active-class=""
    >
      <div class="icon">
        <Icon :type="item.icon" />
      </div>
      <span>{{ item.title }}</span>
    </RouterLink>
  </div>
</template>

<script>
import Icon from "@/components/Icon";
export default {
  components: {
    Icon,
  },
  data() {
    return {
      links: [
        {
          name: "Home",
          title: "首页",
          icon: "home",
          exact: true, // 该路径是否需要 精确匹配
        },
        {
          name: "Blog",
          title: "文章",
          icon: "blog",
          exact: false, // 只要当前路径以路由名称==对应的路径开头，当前菜单就是选中的
        },
        {
          name: "About",
          title: "关于我",
          icon: "about",
          exact: true,
        },
        {
          name: "Project",
          title: "项目&效果",
          icon: "code",
          exact: true,
        },
        {
          name: "Message",
          title: "留言板",
          icon: "chat",
          exact: true,
        },
      ],
    };
  },
};
</script>

<style lang="less" scoped>
@import "~@/style/var.less";
.menu-container {
  a {
    display: flex;
    align-items: center;
    padding: 0 50px;
    color: @gray;
    height: 45px;
    .icon {
      width: 24px;
    }
    &:hover {
      color: #fff;
    }
    &.selected {
      background-color: darken(@words, 2%);
    }
  }
}
</style>